package com.example.controller;

import com.example.document.EsItem;
import com.example.pojo.Item;
import com.example.service.EsItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/esItem")
public class EsItemController {
    @Autowired
    private EsItemService esItemService;

    @GetMapping("/queryById/{id}")
    public EsItem queryById(@PathVariable("id") Long id){
        return esItemService.queryById(id);
    }

    @GetMapping("queryByPrefix")
    public List<EsItem> queryByPrefix(String keyWord){
        System.out.println("请求的前缀：" + keyWord);
        return esItemService.queryByPrefix(keyWord);
    }

    @PostMapping("save")
    public void save(@RequestBody Item item){
        System.out.println("保存：" + item);
        esItemService.save(item);
    }
    @PostMapping("update")
    public void update(@RequestBody Item item){
        System.out.println("修改：" + item);
        esItemService.update(item);
    }

    @DeleteMapping("deleteById")
    public void deleteById(Long id){
        System.out.println("删除" + id);
        esItemService.deleteById(id);
    }


}
